package com.mine.dubbo.zookeeper;

import org.apache.zookeeper.*;

import java.util.concurrent.CountDownLatch;

public class ZooKeeperClient {
    public static void main(String[] args) throws Exception {
        String zkHost = "118.24.229.66:2181";
        CountDownLatch countDownLatch = new CountDownLatch(1);
        ZooKeeper client = new ZooKeeper(zkHost, 4000000, new Watcher() {
            @Override
            public void process(WatchedEvent event) {
                System.out.println(event.getState());
                countDownLatch.countDown();
            }
        });
        countDownLatch.await();
        System.out.println(client.getState());

        client.create("/my/wang", "123123".getBytes(), ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
        client.delete("/my/wang", client.exists("/my/wang", false).getVersion());

        client.close();
        System.out.println(client.getState());
    }
}
